package com.etb.wisdom.eframe.org.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.etb.web.action.ETBAction;
import com.etb.web.eui.utils.EuiUtil;
import com.etb.wisdom.eframe.auth.AuthConstant.AuthType;
import com.etb.wisdom.eframe.auth.AuthConstant.PartyType;
import com.etb.wisdom.eframe.model.OrgEmployee;
import com.etb.wisdom.eframe.org.service.OrgEmployeeService;

@Action("emp")
@Namespace("/eframe/org/employee")
public class OrgEmployeeAction extends ETBAction<OrgEmployee> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1372763751046344910L;

	@Autowired
	public OrgEmployeeService empService;
	
	@Override
	public void save() {
		empService.save(dataObject, newPassword);
	}
	
	public void getUnauthList() {
		String empid = request.getParameter("empid");
		Map<String, Object> hqlParams = new HashMap<String, Object>();
		hqlParams.put("partyid", empid);
		hqlParams.put("partytype", PartyType.employee.toString());
		hqlParams.put("authtype", AuthType.role.toString());
		List list = service.queryByNamedsql("query.eframe.framework.auth.getUnauthList", hqlParams);
		EuiUtil.toGrid(list, null);
	}
	
	public void getAuthList() {
		String empid = request.getParameter("empid");
		Map<String, Object> hqlParams = new HashMap<String, Object>();
		hqlParams.put("partyid", empid);
		hqlParams.put("partytype", PartyType.employee.toString());
		hqlParams.put("authtype", AuthType.role.toString());
		List list = service.queryByNamedsql("query.eframe.framework.auth.getAuthList", hqlParams);
		EuiUtil.toGrid(list, null);
	}
	
	public void saveRole() {
		String addRoleIds = request.getParameter("addRoleIds");
		String delRoleIds = request.getParameter("delRoleIds");
		String empId = request.getParameter("empid");
		empService.saveRole(empId, addRoleIds, delRoleIds);
	}
	
	//辅助更新时“密码默认为空不改变”的规则
	private String newPassword;
	public String getNewPassword() {
		return newPassword;
	}
	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}
}